package com.whq.thrift.api.web.admin.service.admin.impl;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.whq.thrift.api.common.spring.datasource.DataSourceContextHolder;
import com.whq.thrift.api.web.admin.db.admin.PermissionUri;
import com.whq.thrift.api.web.admin.db.admin.PermissionUriMapper;
import com.whq.thrift.api.web.admin.db.admin.UserInfo;
import com.whq.thrift.api.web.admin.db.admin.UserMermission;
import com.whq.thrift.api.web.admin.service.admin.PermissionUriService;

@Service
public class PermissionUriServiceImpl implements PermissionUriService {
	@Autowired
	private PermissionUriMapper permissionUriMapper;

	public void addRecord(PermissionUri record) {
		DataSourceContextHolder.set("dataSourceAdmin");
		if (record == null) {
			return;
		}
		Date now = new Date();
		record.setCreateTime(now);
		record.setUpdateTime(now);

		this.permissionUriMapper.addRecord(record);
	}

	public List<PermissionUri> findRecordsByMap(Map<String, Object> whereParams, int beginIndex, int maxCount) {
		DataSourceContextHolder.set("dataSourceAdmin");
		if(whereParams==null){
			whereParams=new HashMap<String, Object>(0);
		}
		
		whereParams.put("beginIndex", beginIndex);
		whereParams.put("maxCount", maxCount);
		
		return this.permissionUriMapper.getSelectRecrodByMap(whereParams);
	}

	public void updateRecord(PermissionUri record) {
		DataSourceContextHolder.set("dataSourceAdmin");
		if(record==null){
			return;
		}
		
		Date now=new Date();
		record.setUpdateTime(now);
		this.permissionUriMapper.updRecord(record);
	}

	public void deleteRecord(String id) {
		DataSourceContextHolder.set("dataSourceAdmin");
		this.permissionUriMapper.delRecord(id);
	}

	public int findRecordCount(Map<String, Object> whereParams) {
		DataSourceContextHolder.set("dataSourceAdmin");
		return this.permissionUriMapper.findRecordsCount(whereParams);
	}

	public PermissionUri findRecordById(String id) {
		DataSourceContextHolder.set("dataSourceAdmin");
		return this.permissionUriMapper.getSelectRecrodByKey(id);
	}

	public PermissionUri findRecordByUri(String id) {
		DataSourceContextHolder.set("dataSourceAdmin");
		return this.permissionUriMapper.getSelectRecrodByUri(id);
	}

	public List<UserInfo> findUserInfoByMap() {
		DataSourceContextHolder.set("dataSourceAdmin");
		return this.permissionUriMapper.findUserInfoByMap();
	}

	public List<UserMermission> findUserMermissionById(String id) {
		DataSourceContextHolder.set("dataSourceAdmin");
		return this.permissionUriMapper.findUserMermissionById(id);
	}

	public void delUserPermission(String id) {
		DataSourceContextHolder.set("dataSourceAdmin");
		this.permissionUriMapper.delUserPermission(id);
	}

	public void addUserMermission(UserMermission record) {
		DataSourceContextHolder.set("dataSourceAdmin");
		if(record==null){
			return;
		}
		this.permissionUriMapper.addUserPermission(record);
	}
}
